<template>
	<view class="page">
		<view class="List">
			<button class="li" @click="daka">打卡</button>
		</view>

	</view>
</template>

<script>
	import {
		daka,
		ConvertCoordinate
	} from '@/utils/api.js'
	export default {
		components: {},
		data() {
			return {
				gps: false,
				jingdu: '',
				weidu: '',
				Address: '',

			}
		},
		onLoad() {
			this.getLocation()
		},
		methods: {
			getLocation() {
				this.Address=''
				uni.getLocation({
					type: 'wgs84',
					success: async (res) => {
						// res.longitude,res.latitude分别为当前经度，纬度
						this.jingdu = res.longitude,
							this.weidu = res.latitude,
							console.log('经度：', res.longitude, '维度:', res.latitude);
						console.log('经度：', this.jingdu, '维度:', this.weidu)
						const response = await ConvertCoordinate({
							Locations: [res.longitude, res.latitude].join(',')
							
							// Locations: [120.31108093261624,30.303726196289155].join(',')
						})
						console.log(response.Data.regeocode)
						this.Address = response.Data.regeocode
						// if (response.Code === 200) {
						// 	const {
						// 		province,
						// 		city,
						// 		district,
						// 		township
						// 	} = response.Data.regeocode.addressComponent
						// 	const address = response.Data.regeocode.formatted_address
						// 	this.$store.commit('$uStore', {
						// 		name: 'vx_city',
						// 		value: {
						// 			province,
						// 			city,
						// 			district,
						// 			township,
						// 			address
						// 		}
						// 	})
						// 	this.gps = true
						// 	console.log(this.gps);
						// 	// if (tag) {
						// 	//   uni.navigateTo({
						// 	//     url: '/pages/login/index'
						// 	//   })
						// 	// }
						// }
					},
					fail: (err) => {
						console.log(err)
						// this.gps = false
						// uni.showModal({
						// 	title: '提示',
						// 	content: '使用本设备时，请开启手机定位！',
						// 	showCancel: false,
						// 	success: (res) => {
						// 		if (res.confirm) {
						// 			console.log('用户点击确定');
						// 			uni.openSetting({
						// 				success: function(res) {
						// 					// 在成功回调中判断用户是否已开启位置权限，并进行相应处理
						// 					if (res.authSetting[
						// 						'scope.userLocation']) {
						// 						// 用户已开启位置权限，可以重新调用 uni.getLocation 获取位置信息
						// 						console.log('调用');
						// 					}
						// 				}
						// 			});
						// 		}
						// 	}
						// });
					}
				});
			},
			daka() {
				console.log('点击打卡');
				var currentDate = new Date();
				console.log('当前时间:', currentDate, );
				daka({
						Userid: (Math.floor(Math.random() * 1000000)).toString(),
						Name: "测试"+(Math.floor(Math.random() * 1000000)).toString(),
						Phonenumber: this.$store.state.vx_u_info.Phone,
						Latitude:  (this.weidu).toString(),
						Longitude: (this.jingdu).toString(),
						Address: this.Address.formatted_address,
						Positiontime: currentDate
				}).then(res=>{
					if(res.Code===200){
						uni.showModal({
							content: '打卡成功',
							showCancel: false,
							success(res) {
							
							}
						})
					}
					console.log('打卡结果',res);
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	.page {
		width: 100vw;
		height: 100vh;
		position: relative;
		display: flex;
		flex-direction: column;

		.List {
			margin: 500rpx auto;
			// width: 500rpx;
			// height: 80rpx;

			.li {
				margin: 50rpx auto;
				width: 618rpx;
				height: 94rpx;
				text-align: center;
				line-height: 94rpx;
				border-radius: 16rpx;
				background-color: #1677FF;
				color: #fff;
				border-radius: 8rpx 8rpx 8rpx 8rpx;
				font-size: 36rpx;
				font-weight: 400;
			}
		}
	}
</style>